﻿using System;
using Microsoft.Data.Sqlite;
using MyTinnyApi.model;
using TreeView.Maui.Core;

namespace MyTinnyApi.util
{
	public class FolderUtil
	{
		public static int InserFolder(TreeViewNode folder, AppDbContext db)
		{
			return DbUtil.ExecuteInsert($"insert into t_folders (Name, ParentId, ShowOrder) values (@p1, @p2, (select COALESCE(MAX(ShowOrder) + 1, 1) from t_folders))", new[]
			{
				new SqliteParameter("@p1", folder.Name),
                new SqliteParameter("@p2", folder.ParentId)
            });
		}

        public static int InserFolder(Folder folder, AppDbContext db)
        {
			db.Folder.Add(folder);
			db.SaveChanges();
			return folder.Id;
        }

    }
}

